package org.jeecg.modules.report.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.report.vo.departstore.CustomerOrderVO;
import org.jeecg.modules.report.vo.departstore.DepartStoreData;

public interface DepartStoreMapper {
	
	/**
	 * 查询客户订单（状态是进入生产做货状态后的订单 status>=4）
	 * @return
	 */
	@Select("select b.cus_code,b.cus_name,a.count,a.shipment_count from order_info a left join customer_info b on a.customer_info_id = b.id where a.status>=4 group by a.customer_info_id order by b.create_time")
	public List<CustomerOrderVO> getCustomerOrderVOList();

	/**
	 * 查询客户订单在各部门的存货数据列表
	 * @param customerCodeList
	 * @return
	 */
	@Select("<script>"
			+ " SELECT a.org_code as orgCode,h.cus_code as cusCode,SUM( CASE WHEN d.store_status = 1 THEN d.count ELSE 0 END ) AS count FROM"
			+ " sys_depart a LEFT JOIN working_order_record d ON a.org_code = d.receive_dept"
			+ " LEFT JOIN working_order e ON e.id = d.working_order_id LEFT JOIN style_customer_info f ON f.id = e.style_cus_info_id"
			+ " LEFT JOIN order_info g ON g.id = e.order_info_id LEFT JOIN customer_info h ON g.customer_info_id = h.id"
			+ " where h.cus_code in "
			+ " <foreach item='item' index='index' collection='customerCodeList' open='(' separator=',' close=')'>"
			+ " #{item}"
            + " </foreach>"
			+ " GROUP BY h.cus_code"
            + " </script>")
	public List<DepartStoreData> getDepartStoreDataList(@Param("customerCodeList") List<String> customerCodeList);
}
